﻿<!DOCTYPE html>
<html ng-app="myApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
	<meta charset="utf-8" />
    <script src="https://cdn.bootcss.com/angular.js/1.7.0/angular.min.js"></script>
    <script type="text/javascript">

        //直接用自定义的变量self,将会被angularJs认为引用名称为self的服务
        //function Controller(self) {
        function Controller($scope, $sce) {//引用$scope服务（this当前对象）、$sce服务（安全）
            $scope.helloWorld = function () {
                return $sce.trustAsHtml("<h3>Hello,world!</h3>");
            };
        };
        //声明模块时，模块名称后必须要有一个数组，哪怕是空的也好
        //否则，angularJs会认为你在引用它
        var app = angular.module("myApp", []);
        app.controller("Controller", Controller);
    </script>
</head>
<!-- 错误代码
    自1.4版本开始，不可以直接使用全局的函数作为控制器，需配合ng-app
    angular.js:14996 Error: [$controller:ctrlreg] http://errors.angularjs.org/1.7.0/$controller/ctrlreg?p0=Controller
<body ng-controller="Controller" ng-bind-html="helloWorld()">

</body>
    直接使用全局的ng-app也会导致错误:
    angular.js:88 Uncaught Error: [$injector:nomod] http://errors.angularjs.org/1.7.0/$injector/nomod?p0=myApp

    angular.js:14996 Error: [$controller:ctrlreg] http://errors.angularjs.org/1.7.0/$controller/ctrlreg?p0=Controller
<body ng-app ng-controller="Controller" ng-bind-html="helloWorld()">

</body>

    ng-app定义放在调用脚本之后：
        angular.js:88 Uncaught Error: [$injector:nomod] http://errors.angularjs.org/1.7.0/$injector/nomod?p0=myApp

<body ng-app="myApp" ng-controller="Controller" ng-bind-html="helloWorld()">

</body>
    -->
<body ng-controller="Controller" >
    <div ng-bind-html="helloWorld()">

    </div>
</body>
</html>
